*&---------------------------------------------------------------------*
*& 包含               ZFIU025_F01
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Form FRM_GET_DATA
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM FRM_GET_DATA .
  SELECT B~JSDDH
         B~JSDHH
         B~ZYSFPHM
         A~ZYWLX
         A~JSDLX
         A~JSDZT
         A~VORGANG
         A~BUKRS
         A~LIFNR
         A~ZFPHM
         A~ZHSJE
         A~ZHJSE
         A~ZHJSE_GX
         A~ZBHSJE
         A~ZBHSJE_GX
*         A~MWSZK
*         A~ZFPSL
         A~WAERS
         B~EBELN
         B~EBELP
         B~BSART
         B~WERKS
        " B~LGORT
         B~CHARG
         B~MATNR
         B~TXZ01
         B~ERFMG
         B~ERFME
         B~WRBTR
         B~BEZNK
         B~MWSKZ
         B~ZFPSL
         B~ZFPSE
         B~MBLNR
         B~MJAHR
         B~ZEILE
         B~SHEET_NO
         B~COND_TYPE
         B~GL_HKONT
         B~GL_KOSTL
         B~GL_ZUONR
         B~GL_SGTXT
         B~GL_SHKZG
         B~GL_WRBTR
         B~GL_MWSKZ
         B~GL_ZFPSL
         B~GL_ZFPSE
         A~SGTXT
         A~CRNAM
         A~CRDAT
         A~CRTIM
         A~CHNAM
         A~CHDAT
         A~CHTIM
         A~DOCID
         A~BELNR
         A~GJAHR
         C~NAME1 AS LIFNR_NAME
         D~BATXT AS BSART_TXT
    INTO CORRESPONDING FIELDS OF TABLE GT_RESULT
    FROM ZFIT079_HEAD AS A
    JOIN ZFIT079_ITEM AS B
      ON A~JSDDH = B~JSDDH
    LEFT JOIN LFA1 AS C
      ON A~LIFNR = C~LIFNR
    LEFT JOIN T161T AS D
      ON B~BSART = D~BSART
     AND D~SPRAS = SY-LANGU
   WHERE A~JSDDH IN S_JSDDH
     AND A~DOCID IN S_DOCID
     AND A~ZYWLX IN S_ZYWLX
     AND A~JSDLX IN S_JSDLX
     AND A~JSDZT IN S_JSDZT
     AND A~BUKRS IN S_BUKRS
     AND A~LIFNR IN S_LIFNR
     AND A~ZFPHM IN S_ZFPHM
     AND A~CRNAM IN S_CRNAM
     AND A~SGTXT IN S_SGTXT
     AND B~ZYSFPHM IN S_YSFPH
     AND B~EBELN IN S_EBELN
     AND B~BSART IN S_BSART
     AND B~WERKS IN S_WERKS
     AND B~CHARG IN S_CHARG
     AND B~MATNR IN S_MATNR
     AND B~MBLNR IN S_MBLNR
     AND B~MJAHR IN S_MJAHR
     AND B~SHEET_NO IN S_SHENO
     AND B~COND_TYPE IN S_CNDTY
     AND B~GL_HKONT IN S_HKONT
     AND B~GL_KOSTL IN S_KOSTL.

  IF SY-SUBRC <> 0.
    MESSAGE TEXT-M01 TYPE 'S' DISPLAY LIKE 'E'.
    LEAVE LIST-PROCESSING.
  ENDIF.

  SORT GT_RESULT BY JSDDH JSDHH.
  DELETE ADJACENT DUPLICATES FROM GT_RESULT COMPARING JSDDH JSDHH.

  LOOP AT GT_RESULT.
    PERFORM FRM_READ_DOMAIN_TEXT USING GT_RESULT-ZYWLX 'ZDO_ZYWLX1' CHANGING GT_RESULT-ZYWLX_TXT.
    PERFORM FRM_READ_DOMAIN_TEXT USING GT_RESULT-JSDLX 'ZDO_JSDLX'  CHANGING GT_RESULT-JSDLX_TXT.
    PERFORM FRM_READ_DOMAIN_TEXT USING GT_RESULT-JSDZT 'ZDO_JSDZT'  CHANGING GT_RESULT-JSDZT_TXT.
    PERFORM FRM_READ_DOMAIN_TEXT USING GT_RESULT-VORGANG 'MRM_VORGANG'  CHANGING GT_RESULT-VORGANG_TXT.


    IF GT_RESULT-CHDAT IS NOT INITIAL.
      GT_RESULT-DATE_SORT = GT_RESULT-CHDAT.
    ELSE.
      GT_RESULT-DATE_SORT = GT_RESULT-CRDAT.
    ENDIF.

    IF GT_RESULT-CHTIM IS NOT INITIAL.
      GT_RESULT-TIME_SORT = GT_RESULT-CHTIM.
    ELSE.
      GT_RESULT-TIME_SORT = GT_RESULT-CRTIM.
    ENDIF.

    MODIFY GT_RESULT.
  ENDLOOP.

  SORT GT_RESULT BY DATE_SORT DESCENDING TIME_SORT DESCENDING JSDDH JSDHH.

ENDFORM.
*&---------------------------------------------------------------------*
*& Form FRM_ALV_DISPLAY
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM FRM_ALV_DISPLAY .
  DATA:
    LR_DISPLAY   TYPE REF TO CL_SALV_DISPLAY_SETTINGS,
    LR_FUNC_LIST TYPE REF TO CL_SALV_FUNCTIONS_LIST,
    LR_EVENTS    TYPE REF TO CL_SALV_EVENTS_TABLE,
    LR_SELECTS   TYPE REF TO CL_SALV_SELECTIONS,
    LR_COLUMNS   TYPE REF TO CL_SALV_COLUMNS_TABLE,
    LR_COLUMN    TYPE REF TO CL_SALV_COLUMN_TABLE,
    LR_LAYOUT    TYPE REF TO CL_SALV_LAYOUT,
    LS_DDIC      TYPE SALV_S_DDIC_REFERENCE,
    LS_KEY       TYPE SALV_S_LAYOUT_KEY.

  TRY.
      CL_SALV_TABLE=>FACTORY(
        IMPORTING
          R_SALV_TABLE = GR_TABLE
        CHANGING
          T_TABLE      = GT_RESULT[]
      ).
    CATCH CX_SALV_MSG.
  ENDTRY.

  "设置列Lable
  LR_COLUMNS = GR_TABLE->GET_COLUMNS( ).
  LR_COLUMNS->SET_OPTIMIZE( 'X' ).
  LR_COLUMNS->SET_KEY_FIXATION( 'X' ).

  "显示设置
  LR_DISPLAY = GR_TABLE->GET_DISPLAY_SETTINGS( ).
  LR_DISPLAY->SET_STRIPED_PATTERN( 'X' ). "设置颜色间隔显示

  "设置选择模式
  LR_SELECTS = GR_TABLE->GET_SELECTIONS( ).
  LR_SELECTS->SET_SELECTION_MODE( CL_SALV_SELECTIONS=>IF_SALV_C_SELECTION_MODE~CELL ).

  "STAUTS ALV 标准功能
*  LR_FUNC_LIST = GR_TABLE->GET_FUNCTIONS( ).
*  LR_FUNC_LIST->SET_ALL( 'X' ).

  "设置ALV自定义按钮功能
  GR_TABLE->SET_SCREEN_STATUS(
    PFSTATUS      = '9000'
    REPORT        = SY-REPID
    SET_FUNCTIONS = GR_TABLE->C_FUNCTIONS_ALL ).

  "打开Layout保存功能
  LR_LAYOUT = GR_TABLE->GET_LAYOUT( ).
  LS_KEY-REPORT = SY-REPID.
  LR_LAYOUT->SET_KEY( LS_KEY ).
  LR_LAYOUT->SET_DEFAULT( ABAP_TRUE ).
  LR_LAYOUT->SET_SAVE_RESTRICTION( IF_SALV_C_LAYOUT=>RESTRICT_NONE ).

  " Add Hotspot Handlers
  LR_EVENTS = GR_TABLE->GET_EVENT( ).
  CREATE OBJECT GR_EVENTS_HANDLER. "type ref to lcl_events.
  SET HANDLER GR_EVENTS_HANDLER->ON_LINK_CLICK   FOR LR_EVENTS.
  SET HANDLER GR_EVENTS_HANDLER->ON_USER_COMMAND FOR LR_EVENTS.

  TRY .
      LR_COLUMN  ?= LR_COLUMNS->GET_COLUMN( 'JSDDH' ).
      LR_COLUMN->SET_CELL_TYPE( IF_SALV_C_CELL_TYPE=>HOTSPOT ).
    CATCH CX_SALV_NOT_FOUND.
  ENDTRY.

  TRY .
      LR_COLUMN  ?= LR_COLUMNS->GET_COLUMN( 'DOCID' ).
      LR_COLUMN->SET_CELL_TYPE( IF_SALV_C_CELL_TYPE=>HOTSPOT ).
    CATCH CX_SALV_NOT_FOUND.
  ENDTRY.

  TRY .
      LR_COLUMN  ?= LR_COLUMNS->GET_COLUMN( 'BELNR' ).
      LR_COLUMN->SET_CELL_TYPE( IF_SALV_C_CELL_TYPE=>HOTSPOT ).
    CATCH CX_SALV_NOT_FOUND.
  ENDTRY.

  TRY .
      LR_COLUMN  ?= LR_COLUMNS->GET_COLUMN( 'EBELN' ).
      LR_COLUMN->SET_CELL_TYPE( IF_SALV_C_CELL_TYPE=>HOTSPOT ).
    CATCH CX_SALV_NOT_FOUND.
  ENDTRY.

  TRY .
      LR_COLUMN  ?= LR_COLUMNS->GET_COLUMN( 'MBLNR' ).
      LR_COLUMN->SET_CELL_TYPE( IF_SALV_C_CELL_TYPE=>HOTSPOT ).
    CATCH CX_SALV_NOT_FOUND.
  ENDTRY.


  TRY .
      LR_COLUMN  ?= LR_COLUMNS->GET_COLUMN( 'ZYWLX' ).
      LS_DDIC-TABLE = 'ZFIT079_HEAD'.
      LS_DDIC-FIELD = 'ZYWLX'.
      LR_COLUMN->SET_DDIC_REFERENCE( LS_DDIC ).
      LR_COLUMN->SET_VISIBLE( ABAP_FALSE ).
    CATCH CX_SALV_NOT_FOUND.
  ENDTRY.

  TRY .
      LR_COLUMN  ?= LR_COLUMNS->GET_COLUMN( 'JSDLX' ).
      LS_DDIC-TABLE = 'ZFIT079_HEAD'.
      LS_DDIC-FIELD = 'JSDLX'.
      LR_COLUMN->SET_DDIC_REFERENCE( LS_DDIC ).
      LR_COLUMN->SET_VISIBLE( ABAP_FALSE ).
    CATCH CX_SALV_NOT_FOUND.
  ENDTRY.

  TRY .
      LR_COLUMN  ?= LR_COLUMNS->GET_COLUMN( 'JSDZT' ).
      LS_DDIC-TABLE = 'ZFIT079_HEAD'.
      LS_DDIC-FIELD = 'JSDZT'.
      LR_COLUMN->SET_DDIC_REFERENCE( LS_DDIC ).
      LR_COLUMN->SET_VISIBLE( ABAP_FALSE ).
    CATCH CX_SALV_NOT_FOUND.
  ENDTRY.

  TRY .
      LR_COLUMN  ?= LR_COLUMNS->GET_COLUMN( 'VORGANG' ).
      LS_DDIC-TABLE = 'ZFIT079_HEAD'.
      LS_DDIC-FIELD = 'VORGANG'.
      LR_COLUMN->SET_DDIC_REFERENCE( LS_DDIC ).
      LR_COLUMN->SET_VISIBLE( ABAP_FALSE ).
    CATCH CX_SALV_NOT_FOUND.
  ENDTRY.

  TRY .
      LR_COLUMN  ?= LR_COLUMNS->GET_COLUMN( 'BSART' ).
      LS_DDIC-TABLE = 'ZFIT079_ITEM'.
      LS_DDIC-FIELD = 'BSART'.
      LR_COLUMN->SET_DDIC_REFERENCE( LS_DDIC ).
      LR_COLUMN->SET_VISIBLE( ABAP_FALSE ).
    CATCH CX_SALV_NOT_FOUND.
  ENDTRY.

  TRY .
      LR_COLUMN  ?= LR_COLUMNS->GET_COLUMN( 'MWSKZ' ).
      LS_DDIC-TABLE = 'ZFIT079_ITEM'.
      LS_DDIC-FIELD = 'MWSKZ'.
      LR_COLUMN->SET_DDIC_REFERENCE( LS_DDIC ).
    CATCH CX_SALV_NOT_FOUND.
  ENDTRY.

  TRY .
      LR_COLUMN  ?= LR_COLUMNS->GET_COLUMN( 'GL_MWSKZ' ).
      LS_DDIC-TABLE = 'ZFIT079_ITEM'.
      LS_DDIC-FIELD = 'GL_MWSKZ'.
      LR_COLUMN->SET_DDIC_REFERENCE( LS_DDIC ).
    CATCH CX_SALV_NOT_FOUND.
  ENDTRY.


  TRY .
      LR_COLUMN  ?= LR_COLUMNS->GET_COLUMN( 'ZYWLX_TXT' ).
      LR_COLUMN->SET_SHORT_TEXT( TEXT-H01 ).
      LR_COLUMN->SET_MEDIUM_TEXT( TEXT-H01 ).
      LR_COLUMN->SET_LONG_TEXT( TEXT-H01 ).
    CATCH CX_SALV_NOT_FOUND.
  ENDTRY.


  TRY .
      LR_COLUMN  ?= LR_COLUMNS->GET_COLUMN( 'JSDLX_TXT' ).
      LR_COLUMN->SET_SHORT_TEXT( TEXT-H02 ).
      LR_COLUMN->SET_MEDIUM_TEXT( TEXT-H02 ).
      LR_COLUMN->SET_LONG_TEXT( TEXT-H02 ).
    CATCH CX_SALV_NOT_FOUND.
  ENDTRY.

  TRY .
      LR_COLUMN  ?= LR_COLUMNS->GET_COLUMN( 'JSDZT_TXT' ).
      LR_COLUMN->SET_SHORT_TEXT( TEXT-H03 ).
      LR_COLUMN->SET_MEDIUM_TEXT( TEXT-H03 ).
      LR_COLUMN->SET_LONG_TEXT( TEXT-H03 ).
    CATCH CX_SALV_NOT_FOUND.
  ENDTRY.

  TRY .
      LR_COLUMN  ?= LR_COLUMNS->GET_COLUMN( 'VORGANG_TXT' ).
      LR_COLUMN->SET_SHORT_TEXT( TEXT-H05 ).
      LR_COLUMN->SET_MEDIUM_TEXT( TEXT-H05 ).
      LR_COLUMN->SET_LONG_TEXT( TEXT-H05 ).
    CATCH CX_SALV_NOT_FOUND.
  ENDTRY.

  TRY .
      LR_COLUMN  ?= LR_COLUMNS->GET_COLUMN( 'DOCID' ).
      LR_COLUMN->SET_SHORT_TEXT( TEXT-H04 ).
      LR_COLUMN->SET_MEDIUM_TEXT( TEXT-H04 ).
      LR_COLUMN->SET_LONG_TEXT( TEXT-H04 ).
    CATCH CX_SALV_NOT_FOUND.
  ENDTRY.

  TRY .
      LR_COLUMN  ?= LR_COLUMNS->GET_COLUMN( 'BUKRS' ).
      LR_COLUMN->SET_VISIBLE( ABAP_FALSE ).
    CATCH CX_SALV_NOT_FOUND.
  ENDTRY.

*  TRY .
*      LR_COLUMN  ?= LR_COLUMNS->GET_COLUMN( 'ZYWLX' ).
*      LR_COLUMN->SET_VISIBLE( ABAP_FALSE ).
*    CATCH CX_SALV_NOT_FOUND.
*  ENDTRY.
*
*  TRY .
*      LR_COLUMN  ?= LR_COLUMNS->GET_COLUMN( 'JSDLX' ).
*      LR_COLUMN->SET_VISIBLE( ABAP_FALSE ).
*    CATCH CX_SALV_NOT_FOUND.
*  ENDTRY.
*
*  TRY .
*      LR_COLUMN  ?= LR_COLUMNS->GET_COLUMN( 'JSDZT' ).
*      LR_COLUMN->SET_VISIBLE( ABAP_FALSE ).
*    CATCH CX_SALV_NOT_FOUND.
*  ENDTRY.

  TRY .
      LR_COLUMN  ?= LR_COLUMNS->GET_COLUMN( 'CHNAM' ).
      LR_COLUMN->SET_VISIBLE( ABAP_FALSE ).
    CATCH CX_SALV_NOT_FOUND.
  ENDTRY.

  TRY .
      LR_COLUMN  ?= LR_COLUMNS->GET_COLUMN( 'CHDAT' ).
      LR_COLUMN->SET_VISIBLE( ABAP_FALSE ).
    CATCH CX_SALV_NOT_FOUND.
  ENDTRY.

  TRY .
      LR_COLUMN  ?= LR_COLUMNS->GET_COLUMN( 'CHTIM' ).
      LR_COLUMN->SET_VISIBLE( ABAP_FALSE ).
    CATCH CX_SALV_NOT_FOUND.
  ENDTRY.

  TRY .
      LR_COLUMN  ?= LR_COLUMNS->GET_COLUMN( 'DATE_SORT' ).
      LR_COLUMN->SET_VISIBLE( ABAP_FALSE ).
    CATCH CX_SALV_NOT_FOUND.
  ENDTRY.

  TRY .
      LR_COLUMN  ?= LR_COLUMNS->GET_COLUMN( 'TIME_SORT' ).
      LR_COLUMN->SET_VISIBLE( ABAP_FALSE ).
    CATCH CX_SALV_NOT_FOUND.
  ENDTRY.

  GR_TABLE->DISPLAY( ).
ENDFORM.


FORM FRM_READ_DOMAIN_TEXT  USING    IV_KEY
                                IV_DOMNAME
                       CHANGING CV_TEXT.
  DATA:
    LS_TAB TYPE DD07V,
    LT_TAB TYPE STANDARD TABLE OF DD07V.

  CLEAR CV_TEXT.

  CALL FUNCTION 'DD_DOMVALUES_GET'
    EXPORTING
      DOMNAME        = IV_DOMNAME
      TEXT           = 'X'
    TABLES
      DD07V_TAB      = LT_TAB
    EXCEPTIONS
      WRONG_TEXTFLAG = 1
      OTHERS         = 2.

  IF SY-SUBRC <> 0.
    RETURN.
  ENDIF.

  LOOP AT LT_TAB INTO LS_TAB.
    IF LS_TAB-DOMVALUE_L = IV_KEY.
      CV_TEXT = LS_TAB-DDTEXT.
      EXIT.
    ENDIF.
  ENDLOOP.
ENDFORM.                    " READ_DOMAIN_TEXT
